package com.hmall.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.pojo.ItemDoc;
import com.hmall.pojo.RequestParams;
import com.hmall.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
@Slf4j
@Api("ES索引库导入")
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 自动补全
     *
     * @param prefix
     * @return
     */
    @GetMapping("/suggestion")
    @ApiOperation("自动补全")
    public List<String> getSuggestion(@RequestParam("key") String prefix) {
        return searchService.getSuggestion(prefix);
    }

    /**
     * 查询过滤
     *
     * @param params
     * @return
     */
    @PostMapping("/filters")
    @ApiOperation("查询过滤")
    public Map<String,List<String>> getFilters(@RequestBody RequestParams params){
        return searchService.getFilters(params);
    }

    /**
     * 分页查询搜索
     *
     * @param
     * @param
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("分页查询搜索")
    public PageDTO<ItemDoc> search(@RequestBody RequestParams params) {
        return searchService.search(params);
    }
}
